import { post } from '@/request/http'
import { toString } from '@/utils/utils'
import store from '@/store'

/**
 * 供应商-基础资料管理-部门管理 接口
 *
 */

/**
 * 获取列表数据
 */

export const checkDepartmentList = ({
  dptCode,
  dptName,
  dptPredptId,
  PageIndex,
  PageSize
}) =>
  post(
    '/FTKJWLHYPT/basDepartment/queryBasDepartment?SessionId=' +
             store.state.user.SessionId_DX_H,
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            dptCode,
            dptName,
            dptPredptId,
            fltUuid: store.state.user.FLT_UUID_DX_H,
          }
        },
        Orderbys: {},
        PageIndex: {
          FTKJWLHYPT: toString(PageIndex)
        },
        PageSize: {
          FTKJWLHYPT  : toString(PageSize)
        }
      }
    }
  )
/**
 * 新增一行数据
 */

export const addDepartmentList = ({
  // 必填
  dptFltId = '-1',
  dptSeq,
  dptCode,
  dptName,
  dptPredptId
}) =>
  post(
    '/FTKJWLHYPT/basDepartment/addBasDepartment?SessionId=' +
    store.state.user.SessionId_DX_H,
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            dptFltId,
            dptSeq,
            dptCode,
            dptName,
            dptPredptId,
            creator: store.state.user.USR_CODE_DX_H,
            fltUuid: store.state.user.FLT_UUID_DX_H,
          }
        }
      }
    }
  )
/**
 * 编辑一行数据
 */

export const editDepartment = ({
  dptId,
  dptSeq,
  dptCode = '',
  dptName = '',
  dptPredptId = '',
  version, // 版本号
}) =>
  post(
    '/FTKJWLHYPT/basDepartment/editBasDepartment?SessionId=' +
             store.state.user.SessionId_DX_H,
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            dptId,
            dptSeq,
            dptCode,
            dptName,
            dptPredptId,
            lastmodifier: store.state.user.USR_CODE_DX_H,
            version: toString(version)
          }
        }
      }
    }
  )


/**
 * 删除一行数据
 */

export const delDepartment = ({
  dptId,
  version // 版本号
}) =>
  post(
    '/FTKJWLHYPT/basDepartment/delBasDepartment?SessionId=' +
    store.state.user.SessionId_DX_H,
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            dptId,
            lastmodifier: store.state.user.USR_CODE_DX_H,
            version: toString(version)
          }
        }
      }
    }
  )

/* 上级部门下拉接口 */
export const getSDepartment = () =>
  post(
    '/FTKJWLHYPT/basDepartment/queryBasDepartmentTree?SessionId=' +
     store.state.user.SessionId_DX_H,
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            fltUuid: store.state.user.FLT_UUID_DX_H,
          }
        },
        Orderbys: {},
        PageIndex: {
          FTKJWLHYPT: ''
        },
        PageSize: {
          FTKJWLHYPT: ''
        }
      }
    }
  )


// 查看所有用户
export const checkuserList = ({
  dptId,
  fltUuid,
}) =>
  post(
    '/FTKJWLHYPT/basUser/queryBasUser?SessionId=' +
    store.state.user.SessionId_DX_H,
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            dptId,
            fltUuid,
          }
        },
        Orderbys: {},
        PageIndex: {
          FTKJWLHYPT: ''
        },
        PageSize: {
          FTKJWLHYPT: ''
        }
      }
    }
  )
